package com.yuba.front.controller.comment;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.yuba.common.idempotent.annotation.RepeatSubmit;
import com.yuba.common.log.annotation.Log;
import com.yuba.common.web.core.BaseController;
import com.yuba.common.mybatis.core.page.PageQuery;
import com.yuba.common.core.domain.R;
import com.yuba.common.core.validate.AddGroup;
import com.yuba.common.core.validate.EditGroup;
import com.yuba.common.log.enums.BusinessType;
import com.yuba.common.excel.utils.ExcelUtil;
import com.yuba.front.domain.vo.FishSiteCommentsVo;
import com.yuba.front.domain.bo.FishSiteCommentsBo;
import com.yuba.front.service.IFishSiteCommentsService;
import com.yuba.common.mybatis.core.page.TableDataInfo;

/**
 * 钓场评论
 *
 * @author modakai
 * @date 2024-12-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/comment/siteComments")
public class FishSiteCommentsController extends BaseController {

    private final IFishSiteCommentsService fishSiteCommentsService;

    /**
     * 查询钓场评论列表
     */
    @SaCheckPermission("comment:siteComments:list")
    @GetMapping("/list")
    public TableDataInfo<FishSiteCommentsVo> list(FishSiteCommentsBo bo, PageQuery pageQuery) {
        return fishSiteCommentsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出钓场评论列表
     */
    @SaCheckPermission("comment:siteComments:export")
    @Log(title = "钓场评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(FishSiteCommentsBo bo, HttpServletResponse response) {
        List<FishSiteCommentsVo> list = fishSiteCommentsService.queryList(bo);
        ExcelUtil.exportExcel(list, "钓场评论", FishSiteCommentsVo.class, response);
    }

    /**
     * 获取钓场评论详细信息
     *
     * @param commentsId 主键
     */
    @SaCheckPermission("comment:siteComments:query")
    @GetMapping("/{commentsId}")
    public R<FishSiteCommentsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long commentsId) {
        return R.ok(fishSiteCommentsService.queryById(commentsId));
    }

    /**
     * 新增钓场评论
     */
    @SaCheckPermission("comment:siteComments:add")
    @Log(title = "钓场评论", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody FishSiteCommentsBo bo) {
        return toAjax(fishSiteCommentsService.insertByBo(bo));
    }

    /**
     * 修改钓场评论
     */
    @SaCheckPermission("comment:siteComments:edit")
    @Log(title = "钓场评论", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FishSiteCommentsBo bo) {
        return toAjax(fishSiteCommentsService.updateByBo(bo));
    }

    /**
     * 删除钓场评论
     *
     * @param commentsIds 主键串
     */
    @SaCheckPermission("comment:siteComments:remove")
    @Log(title = "钓场评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{commentsIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] commentsIds) {
        return toAjax(fishSiteCommentsService.deleteWithValidByIds(List.of(commentsIds), true));
    }
}
